package com.glory.dgcpcpda.activity.mfg;

import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.glory.dgcpcpda.R;
import com.glory.dgcpcpda.activity.cpc.CpcDaQtyUpdatedActivity;
import com.glory.dgcpcpda.adapter.DivideLotAdapter;
import com.glory.dgcpcpda.adapter.PackageCheckAdapter;
import com.glory.dgcpcpda.base.BaseActivity;
import com.glory.dgcpcpda.base.Constant;
import com.glory.dgcpcpda.entity.LotInfoEntity;
import com.glory.dgcpcpda.entity.response.BaseResponseBean;
import com.glory.dgcpcpda.utils.LotUtils;
import com.glory.dgcpcpda.utils.NetUtils;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_DialogEntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;
import butterknife.BindView;
import butterknife.OnClick;

public class DivideLotActivity extends BaseActivity {


    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.etLot)
    FreeUI_ClearEditText etLot;
    @BindView(R.id.etLotQty)
    FreeUI_ClearEditText etLotQty;
    @BindView(R.id.tvBaseSubmit)
    TextView tvBaseSubmit;
    @BindView(R.id.rvDivideLotList)
    RecyclerView rvDivideLotList;
    @BindView(R.id.llMain)
    LinearLayout llMain;

    private DivideLotAdapter mDivideLotAdapter;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_divide_lot;
    }

    @Override
    protected void initView() {
        tvTitle.setText("批次分批");
        tvBaseSubmit.setText("分批");
        setMainLayout(llMain);
        initRecyclerView(rvDivideLotList, this);
        mDivideLotAdapter = new DivideLotAdapter(null);
        rvDivideLotList.setAdapter(mDivideLotAdapter);
    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.tvBaseSubmit)
    public void onViewClicked() {

        if (getText(etLot).equals("")){
            showToast("请扫描批次号",false);
            return;
        }
        if (getText(etLotQty).equals("")){
            showToast("请输入数量",false);
            return;
        }

        FreeUI_EntityCallBack<BaseResponseBean<LotInfoEntity>> callback = new FreeUI_DialogEntityCallBack<BaseResponseBean<LotInfoEntity>>
                (new TypeToken<BaseResponseBean<LotInfoEntity>>() {
                }.getType(), getSupportFragmentManager(), this) {

            @Override
            public void onSuccess(Response<BaseResponseBean<LotInfoEntity>> response) {
                super.onSuccess(response);
                if (response.body().isSuccess(getApplicationContext(), false, getSupportFragmentManager())) {
                    mDivideLotAdapter.setNewData(response.body().getResponse().getBody().getLOTLIST());
                }
            }
            @Override
            public void onError(Response<BaseResponseBean<LotInfoEntity>> response) {
                super.onError(response);
            }
        };
        JsonObject map = new JsonObject();
        map.addProperty("ACTIONTYPE", "LOTSPLIT");
        map.addProperty("LOTID", getText(etLot));
        map.addProperty("MAINQTY", getText(etLotQty));
        NetUtils.requestPostNet("CPC.LOTSPLIT", "TRANSFERMES",this, map, callback);

    }

}
